/* Copyright (c) 2009 - 2010 98Labs Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sbal89.map.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class GadgetServlet extends HttpServlet {
	private Logger log = Logger.getLogger(this.getClass().getName());
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String name = req.getServletPath();
		String[] params = name.split("/");
		log.info(params[1]);
		String key = params[2];
		String type = params[1];
		String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		xml += "<Module>\n" +
			"<ModulePrefs" + 
			"\n\ttitle=\"2010 Election Exchange Map\"" +
			"\n\tdescription=\"An election results visulization tool showing election turnouts per province.\"" +
			"\n\tauthor_location=\"Philippines\"" +
			"\n\twidth=\"480\"" +
			"\n\theight=\"350\" />" +
			"\n<Content type=\"url\" href=\"http://maps-view.electionexchange.ph/"+ type +".gen?key=" + key + "\" />" +
			"\n</Module>";
		resp.setHeader("Pragma", "no-cache");
		resp.setHeader("Expires", "-1");
		resp.setContentType("text/xml");
		PrintWriter pw = resp.getWriter();
		pw.print(xml);
		pw.flush();
	}
}
